/****

    activequant - activestocks.eu

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

	
	contact  : contact@activestocks.eu
    homepage : http://www.activestocks.eu

****/
package org.activequant.dao.hibernate;

import org.activequant.dao.IAccountDao;
import org.activequant.dao.IBalanceBookDao;
import org.activequant.dao.IBalanceEntryDao;
import org.activequant.dao.IBrokerAccountDao;
import org.activequant.dao.ICandleDao;
import org.activequant.dao.IFactoryDao;
import org.activequant.dao.IIndexComponentDao;
import org.activequant.dao.IIndexCompositionDao;
import org.activequant.dao.IOrderBookDao;
import org.activequant.dao.IOrderDao;
import org.activequant.dao.IQuoteDao;
import org.activequant.dao.ISpecificationDao;
import org.activequant.dao.IStoreDao;
import org.activequant.dao.ITradeIndicationDao;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


/**
 * FactoryConfigDao implements IFactoryDao.<br/>
 * Holds the following associated variables:
 * <ul>
 * <li>sessionFactory(SessionFactory)</li>
 * </ul>
 * <br>
 * <b>History:</b><br>
 *  - [16.07.2007] Created (Erik Nijkamp)<br>
 *  - [10.08.2008] Added index classes (Wessel de Roode)<br>
 *
 *  @author Erik Nijkamp
 */
public class FactoryConfigDao implements IFactoryDao {
	/**
	 * private SessionFactory sessionFactory;
	 */
	private SessionFactory sessionFactory;
	/**
	 * Constructs a FactoryConfigDao(implements IFactoryDao), setting its associated sessionFactory(SessionFactory)
	 * with a sessionFactory(SessionFactory) initialized from a resource named <strong>hibernate.cfg.xml</strong>.
	 */
	public FactoryConfigDao() {
		sessionFactory = HibernateUtil.getSessionFactory();
	}
	/**
	 * Constructs a FactoryConfigDao(implements IFactoryDao), setting its associated sessionFactory(SessionFactory)
	 * with a sessionFactory(SessionFactory) initialized from the given config(Configuration).
	 * @param config
	 */
	public FactoryConfigDao(Configuration config) {
		sessionFactory = HibernateUtil.getSessionFactory(config);
	}
	/**
	 * Creates and returns a StoreDao(extends HibernateDaoSupport implements IStoreDao) using the associated sessionFactory(SessionFactory) to set 
	 * its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate)
	 */
	public IStoreDao createStoreDao() {
		return new StoreDao(getSessionFactory());
	}
	/**
	 * Creates and returns an AccountDao(extends DaoSupportBase&lt;Account&gt; implements IAccountDao) using <code>Account.class</code>
	 * to set its associated clazz(Class&lt;Account&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public IAccountDao createAccountDao() {
		return new AccountDao(getSessionFactory());
	}
	/**
	 * Creates and returns a BrokerAccountDao(extends DaoSupportBase&lt;BrokerAccount&gt; implements IBrokerAccountDao) using <code>BrokerAccount.class</code>
	 * to set its associated clazz(Class&lt;BrokerAccount&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public IBrokerAccountDao createBrokerAccountDao() {
		return new BrokerAccountDao(getSessionFactory());
	}
	/**
	 * Creates and returns a QuoteDao(extends MarketDataEntityBase&lt;Quote&gt; implements IQuoteDao) using <code>Quote.class</code> to set its associated clazz(Class&lt;Quote&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public IQuoteDao createQuoteDao() {
		return new QuoteDao(getSessionFactory());
	}
	/**
	 * Creates and returns a CandleDao(extends MarketDataEntityBase&lt;Candle&gt; implements ICandleDao) using <code>Candle.class</code> to set its associated clazz(Class&lt;Candle&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public ICandleDao createCandleDao() {
		return new CandleDao(getSessionFactory());
	}
	/**
	 * Creates and returns an OrderDao(extends DaoSupportBase&lt;Order&gt; implements IOrderDao) using <code>Order.class</code> to set its associated clazz(Class&lt;Order&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public IOrderDao createOrderDao() {
		return new OrderDao(getSessionFactory());
	}
	/**
	 * Creates and returns a TradeIndicationDao(extends MarketDataEntityBase&lt;TradeIndication&gt; implements ITradeIndicationDao) using <code>TradeIndication.class</code> to set its associated clazz(Class&lt;TradeIndication&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public ITradeIndicationDao createTradeIndicationDao() {
		return new TradeIndicationDao(getSessionFactory());
	}
	/**
	 * Creates and returns a SpecificationDao(extends DaoSupportBase&lt;InstrumentSpecification&gt; implements ISpecificationDao) using <code>InstrumentSpecification.class</code> to set its associated clazz(Class&lt;InstrumentSpecification&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public ISpecificationDao createSpecificationDao() {
		return new SpecificationDao(getSessionFactory());
	}
	/**
	 * Creates and returns an OrderBookDao(extends DaoSupportBase&lt;OrderBook&gt; implements IOrderBookDao) using <code>OrderBook.class</code> to set its associated clazz(Class&lt;OrderBook&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public IOrderBookDao createOrderBookDao() {
		return new OrderBookDao(getSessionFactory());
	}
	/**
	 * returns the associated sessionFactory(SessionFactory)
	 * @return
	 */
	protected SessionFactory getSessionFactory() {
        return sessionFactory;
    }
	/**
	 * returns <code>null</code>
	 */
	public IBalanceBookDao createBalanceBookDao() {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * returns <code>null</code>
	 */
	public IBalanceEntryDao createBalanceEntryDao() {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * Creates and returns an IndexComponentDao(extends DaoSupportBase&lt;IndexComponent&gt; implements IIndexComponentDao) using <code>IndexComponent.class</code> to set its associated clazz(Class&lt;IndexComponent&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public IIndexComponentDao createIndexComponentDao() {
		return new IndexComponentDao(getSessionFactory());	
	}
	/**
	 * Creates and returns an IndexCompositionDao(extends DaoSupportBase&lt;IndexComposition&gt; implements IIndexCompositionDao) using <code>IndexComposition.class</code> to set its associated clazz(Class&lt;IndexComposition&gt;).<br/>
	 * The associated sessionFactory(SessionFactory) is used to set its Hibernate SessionFactory and create/initialize its inherited hibernateTemplate(HibernateTemplate).
	 */
	public IIndexCompositionDao createIndexCompositionDao() {
		return new IndexCompositionDao(getSessionFactory());		
	}
}
